
#include <stdio.h>
#include "stdlib.h"
#include "string.h"
#include <rtthread.h>
#include "drv_i2c.h"
#include "slot.h"

#include "define.h"

#define SLOT_ADDR(slot)		(0x00 + ((slot) << 1))

#define Test  0
uint8_t boardslot;

void feed_dog_entry(void *arg)
{	
	fwdgt_config(0x0FFF, FWDGT_PSC_DIV256);
	fwdgt_enable();
	while(1)
	{
		rt_thread_delay(10000);
		fwdgt_counter_reload();
	}
}




int main(void)
{
	rt_thread_t tid;
	
	printf("Application is running...\r\n");

	slot_gpio_init();
	boardslot = get_slot_self();
//	boardslot = 0;
	rt_kprintf("board slot = %d\r\n", boardslot);

	memset(&ipmi_data, 0, sizeof(ipmi_data));
	ipmi_data.board_slot = boardslot;
	if(boardslot==2){
		ipmi_data.slave_add = 0x84;
	}
	else {
		ipmi_data.slave_add = 0x82;
	}
	
	rt_kprintf("slave addr = %02x\r\n", ipmi_data.slave_add);
	ipmi_data.online = 1;

	power_start();
	adc_start();
	
	i2c_init(I2C0, I2C_SLAVE_CH, ipmi_data.slave_add);	
	bus_start(I2C0);
	i2c_init(I2C1, I2C_SLAVE_CH, ipmi_data.slave_add);		
	bus_start(I2C1);

	while(1);	
	return 0;
}

int fputc(int ch, FILE *f)
{
    usart_data_transmit(UART3, (uint8_t)ch);
    while(RESET == usart_flag_get(UART3, USART_FLAG_TBE));
    return ch;
}

int cmd_reboot(int argc, char **argv)
{
	NVIC_SystemReset();
}

FINSH_FUNCTION_EXPORT_ALIAS(cmd_reboot, __cmd_reboot, reboot system.);
